package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.AdvHomeApplyTbl;
import com.amigo.online.provider.manager.model.entity.AdvHomeSourceTbl;
import com.amigo.online.provider.manager.service.AdvHomeApplyTblService;
import com.amigo.online.provider.manager.service.AdvHomeInfoService;
import com.amigo.online.provider.manager.service.AdvHomeSourceTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/advHomeApplyTbl", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AdvHomeApplyTblController extends BaseController {

    @Resource
    private AdvHomeApplyTblService advHomeApplyTblService;

    @Resource
    private AdvHomeInfoService advHomeInfoService;

    @Resource
    private AdvHomeSourceTblService advHomeSourceTblService;

    /**
     * 查询广告申请
     *
     * @param ahat
     * @return
     */
    @PostMapping(value = "/getAdvHomeApplyTblList")
    public ResponseEntity<Response> getAdvHomeApplyTblList(@RequestBody AdvHomeApplyTbl ahat) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(ahat.getPageNo(), 10);
        List<AdvHomeApplyTbl> advHomeApplyTblList = advHomeApplyTblService.findAdvHomeApplyTbl(ahat);

        result.put("advHomeApplyTblList", advHomeApplyTblList);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    /**
     * 添加广告申请
     *
     * @param ahat
     * @return
     */
    @PostMapping(value = "/saveAdvHomeApplyTbl")
    public ResponseEntity<Response> saveAdvAreaTbl(@RequestBody AdvHomeApplyTbl ahat) {

        return success(advHomeApplyTblService.saveAdvHomeApplyTbl(ahat));

    }

    /**
     * 修改广告申请
     *
     * @param ahat
     * @return
     */
    @PutMapping(value = "/updateAdvHomeApplyTbl")
    public ResponseEntity<Response> updateAdvHomeApplyTbl(@RequestBody AdvHomeApplyTbl ahat) {
        return success(advHomeApplyTblService.updateAdvHomeApplyTbl(ahat));
    }

    /**
     * 删除广告申请
     *
     * @param ahat
     * @return
     */
    @DeleteMapping(value = "/deleteAdvHomeApplyTbl")
    public ResponseEntity<Response> deleteAdvHomeApplyTbl(@RequestBody AdvHomeApplyTbl ahat) {
        return success(advHomeApplyTblService.deleteAdvHomeApplyTbl(ahat));
    }

    /**
     * 获取广告详情
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/getAdvHomeApplyTblParticulars")
    public ResponseEntity<Response> getAdvHomeApplyTblParticulars(Long id) {
        return success(advHomeInfoService.findAdvHomeApplyTblParticulars(id));
    }

    /**
     * 审核附近广告
     *
     * @param advNearbyApplyTbl
     * @return
     */
    @PostMapping("/check")
    public ResponseEntity<Response> checkHomeApplyAdv(@RequestBody AdvHomeApplyTbl advHomeApplyTbl) {
        boolean re = advHomeApplyTblService.checkAdv(advHomeApplyTbl);
        return success(re);
    }

    /**
     * 添加广告资源
     *
     * @param advNearbySourceTbl
     * @return
     */
    @PostMapping(value = "/addAdvHomeSourceTbl")
    public ResponseEntity<Response> addAdvHomeSourceTbl(@RequestBody AdvHomeSourceTbl advHomeSourceTbl) {
        boolean re = advHomeSourceTblService.saveAdvHomeSourceTbl(advHomeSourceTbl);
        return success(re);
    }

    /**
     * 修改广告资源
     *
     * @param advHomeSourceTbl
     * @return
     */
    @PostMapping(value = "/updateAdvHomeSourceTbl")
    public ResponseEntity<Response> updateAdvHomeSourceTbl(@RequestBody AdvHomeSourceTbl advHomeSourceTbl) {
        boolean re = advHomeSourceTblService.updateAdvHomeSourceTbl(advHomeSourceTbl);
        return success(re);
    }

}
